package com.homework.action;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.homework.bean.CourseBean;
import com.homework.bean.UserBean;
import com.homework.service.CourseService;


public class ClassAddAction {

	private CourseService courseService;
	private String courseName;
	private String schoolYear;
	private String term;
	private String credit;
	private String courseStart;
	private String courseEnd;
	
	public ClassAddAction() {
		courseService = new CourseService();
	}
	
	public String getCourseName() {
		return courseName;
	}

	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}

	public String getSchoolYear() {
		return schoolYear;
	}

	public void setSchoolYear(String schoolYear) {
		this.schoolYear = schoolYear;
	}

	public String getTerm() {
		return term;
	}

	public void setTerm(String term) {
		this.term = term;
	}

	public String getCredit() {
		return credit;
	}

	public void setCredit(String credit) {
		this.credit = credit;
	}

	public String getCourseStart() {
		return courseStart;
	}

	public void setCourseStart(String courseStart) {
		this.courseStart = courseStart;
	}

	public String getCourseEnd() {
		return courseEnd;
	}

	public void setCourseEnd(String courseEnd) {
		this.courseEnd = courseEnd;
	}

	public String classAdd() throws SQLException {
		// TODO Auto-generated method stub
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		
		// courseBean
		CourseBean courseBean = new CourseBean();
		courseBean.setCourseName(this.getCourseName());
		courseBean.setCredit(this.getCredit());
		courseBean.setSchoolYear(this.getSchoolYear());
		courseBean.setTerm(this.getTerm());
		courseBean.setCourseStart(this.getCourseStart());
		courseBean.setCourseEnd(this.getCourseEnd());
		// userBean
		UserBean userBean = new UserBean();
		userBean.setUserId(String.valueOf(session.getAttribute("userId")));
		
	    courseService.classAdd(courseBean,userBean);
		return "Success";
	}

}
